import request from '@/utils/zyrequest'
import qs from 'qs'
import { getToken } from '@/utils/auth'

export default {

    findRole(id) {
        return request({
            url: '/item/user/rolelist',
            method: 'get',
            params: {
                id: `${id}`
            }
        })
    },

    // 查询全部用户
    selectAllUser(uName,page,size) {
        return request({
            url: '/user/user/allUser',
            method: 'get',
            params: {
                uName: `${uName}`,
                page: `${page}`,
                size: `${size}`
            },
            // headers: {
            //     'token': getToken()
            // }
        })
    },

    // 重置密码
    resetPassword(id) {
        return request({
            url: '/user/user/resetPassword',
            method: 'post',
            params: {
                id: `${id}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 添加新用户
    registerUser(pojo) {
        return request({
            url: '/user/user/register',
            method: 'post',
            data: qs.stringify(pojo),
            headers: {
                'Content-type': 'application/x-www-form-urlencoded',
                // 'token': getToken()
            }
        })
    },

    // 更新用户
    updateUser(pojo) {
        return request({
            url: '/user/user/update',
            method: 'put',
            data: JSON.stringify(pojo),
            headers: {
                'Content-type': 'application/json;charset=UTF-8',
                // 'token': getToken()
            }
        })
    },

    // 删除用户
    deleteUser(id) {
        return request({
            url: '/user/user/delete',
            method: 'delete',
            params: {
                id: `${id}`
            },
            headers: {
                // 'token': getToken()
            }
        })
    },

    // 分配角色
    assignRoles(pojo) {
        return request({
            url: '/item/user/assignRoles',
            method: 'put',
            data: JSON.stringify(pojo),
            headers: {
                'Content-type': 'application/json;charset=UTF-8'
                // 'token': getToken()
            }
        })
    }
}